package com.fan.txl.ui.adapter;

import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by jiajiabao on 17-1-10.
 */

public  abstract class  Adapt<Data> extends RecyclerView.Adapter<Adapt.VHolder> {

    public abstract int getLayoutId();
    protected abstract void bindData(VHolder holder, int position);

    List<Data> mData;
    public Adapt(List<Data> data) {
        mData=data;
    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }

    public static class VHolder extends  RecyclerView.ViewHolder{

        public VHolder(View itemView) {
            super(itemView);
        }
    }





    @Override
    public VHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(),parent,false);
        return new VHolder(view);
    }

    @Override
    public void onBindViewHolder(VHolder holder, int position) {
        bindData(holder,position);
    }

    @Override
    public void onBindViewHolder(VHolder holder, int position, List<Object> payloads) {
        super.onBindViewHolder(holder, position, payloads);
    }
}
